<template>
    <div style="width:100%;height:100%;display: flex;justify-content: center;">
        <p class="total">{{this.chartData.d12}}kw</p>
        <div style="width:100%;height:100%;" id="rightSecond"/>
    </div>
</template>
<script>
    import echarts from 'echarts';
    import mixins from '../minxis';
    export default {
        props: {
            chartData: {
                type: Object,
                default () {
                    return {};
                }
            }
        },
        mixins: [mixins],
        data () {
            return {
                example: null
            };
        },
        watch: {
            chartData: {
                handler (newVal) {
                    if (Object.keys(newVal).length !== 0) {
                        this.init();
                    }
                },
                deep: true,
                immediate: true
            }
        },
        methods: {
            init () {
                this.example = echarts.init(document.getElementById('rightSecond'));
                let option = {
                    tooltip: {
                        formatter: '{a} <br/>{b} : {c}%'
                    },
                    toolbox: {
                        feature: {
                            dataView: {show: false, readOnly: false},
                            magicType: {show: false, type: ['line', 'bar']},
                            restore: {show: false},
                            saveAsImage: {show: false}
                        }
                    },
                    grid: {
                        top: '0%',
                        bottom: '0%',
                        left: '0%',
                        right: '0%',
                        containLabel: true
                    },
                    series: [
                        {
                            name: '当前功率',
                            type: 'gauge',
                            min: 90,
                            max: 100,
                            radius: '90%',
                            detail: {
                                formatter: '{value}%',
                                fontSize: 24
                            },
                            data: [{value: this.chartData.d13, name: '当前功率'}],
                            axisLine: { // 坐标轴线
                                lineStyle: { // 属性lineStyle控制线条样式
                                    color: [[1, '#1e90ff']],
                                    width: 3,
                                    shadowColor: '#fff', // 默认透明
                                    shadowBlur: 10
                                }
                            },
                            axisLabel: { // 坐标轴小标记
                                fontWeight: 'bolder',
                                color: '#fff',
                                shadowColor: '#fff', // 默认透明
                                shadowBlur: 10,
                                formatter: '{value}'
                            },
                            axisTick: { // 坐标轴小标记
                                length: 15, // 属性length控制线长
                                lineStyle: { // 属性lineStyle控制线条样式
                                    color: 'auto',
                                    shadowColor: '#fff', // 默认透明
                                    shadowBlur: 10
                                }
                            },
                            splitLine: { // 分隔线
                                length: 25, // 属性length控制线长
                                lineStyle: { // 属性lineStyle（详见lineStyle）控制线条样式
                                    width: 3,
                                    color: '#fff',
                                    shadowColor: '#fff', // 默认透明
                                    shadowBlur: 10
                                }
                            },
                            pointer: { // 分隔线
                                shadowColor: '#fff', // 默认透明
                                shadowBlur: 5
                            },
                            title: {
                                textStyle: { // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                                    fontWeight: 'bolder',
                                    fontSize: 12,
                                    // fontStyle: 'italic',
                                    color: '#fff',
                                    shadowColor: '#fff', // 默认透明
                                    shadowBlur: 10
                                }
                            }
                            /* detail: {
                                backgroundColor: 'rgba(30,144,255,0.8)',
                                borderWidth: 1,
                                borderColor: '#fff',
                                shadowColor: '#fff', // 默认透明
                                shadowBlur: 5,
                                offsetCenter: [0, '50%'], // x, y，单位px
                                textStyle: { // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                                    fontWeight: 'bolder',
                                    color: '#fff'
                                },
                                formatter: '{value}KWH'
                            } */
                        }
                    ]
                };
                this.example.setOption(option);
                addEventListener('resize', () => {
                    this.example.resize();
                });
            }
        }
    };
</script>
<style scoped>
    .total {
        position: absolute;
        bottom: 0;
        font-size: 1.25vw;
        color: #fff;
        font-weight: 700;
    }
</style>
